<template>
	<view class="item" v-for="item in props.data" :key="item.id">
		<view class="item_top" @click="details">
			<view class="left">
				<view class="price">
					<tagVue v-if="item.status === 1" title="出租中" :bgColor="backgroundColor3" :textColor="textColor3" />
					<tagVue v-else-if="item.status === 0" title="已下架" :bgColor="backgroundColor4" :textColor="textColor4" />
				</view>
				<image :src="item.src" mode=""></image>
			</view>
			<view class="right_price" :style="item.status === 0 ? 'color:#ababab;' : ''">
				<text>{{ item.title }}</text>
				<text style="color: #a79aa7">{{ item.content }}</text>
				<text style="color: #f46363">￥{{ item.price }}/月</text>
			</view>
		</view>
		<view class="item_bottom">
			<view class="resolve" v-if="item.status === 0">
				<button style="background-color: #e6f1ff; color: #006eff" @click="again(item)">重新上架</button>
			</view>
			<view class="edit" v-else>
				<button style="background-color: #e6f1ff; color: #006eff" @click="outRent(item)">租出下架</button>
				<button style="background-color: #006eff; color: #fff">编辑</button>
			</view>
		</view>
	</view>
</template>

<script setup>
import { ref } from 'vue';
import tagVue from '@/components/tag.vue';
import { useMyStore } from '@/stores/myStore.js';
const store = useMyStore();
const props = defineProps(['data']);
const backgroundColor3 = ref('#2ed477');
const textColor3 = ref('#ffffff');
const backgroundColor4 = ref('#d7d7d7');
const textColor4 = ref('#ababab');
const details = () => {
	uni.navigateTo({
		url: '/pages/rentDetail/rentDetail'
	});
};
const again = (item) => {
	uni.showModal({
		content: '是否重新上架该房屋？',
		success: ({ confirm }) => {
			if (confirm) {
				store.getAgain({ ...item, status: 1 });
				uni.showToast({
					icon: 'none', // 设置提示框的图标，这里设置为无图标
					title: '房屋上架成功', // 提示框的标题
					duration: 2000 // 提示框的持续时间，单位为毫秒，这里设置为2000毫秒，即2秒
				});
			}
		}
	});
};
const outRent = (item) => {
	uni.showModal({
		content: '是否下架该房屋？',
		success: ({ confirm }) => {
			if (confirm) {
				store.getOut({ ...item, status: 0 });
				uni.showToast({
					icon: 'none', // 设置提示框的图标，这里设置为无图标
					title: '房屋下架成功', // 提示框的标题
					duration: 2000 // 提示框的持续时间，单位为毫秒，这里设置为2000毫秒，即2秒
				});
			}
		}
	});
};
</script>

<style lang="scss">
.item {
	width: 100%;
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
	padding: 0 30rpx;
	border: 2rpx solid #f2f2f2;
	margin: 30rpx 0;
	border-radius: 10rpx;
	.item_shelf {
		color: #ababab;
	}
	.item_top {
		height: 230rpx;
		display: flex;
		align-items: center;
		justify-content: space-around;
		.left {
			position: relative;
			.price {
				position: absolute;
				top: 0;
				left: 0;
			}
			image {
				width: 220rpx;
				height: 160rpx;
				border-radius: 10rpx;
			}
		}
		.right {
			width: 360rpx;
			height: 160rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			.author {
				display: flex;
				align-items: center;
				justify-content: space-between;
				font-size: 28rpx;
				color: #aab2c8;
			}
		}
		.right_price {
			width: 360rpx;
			height: 160rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
		}
	}
	.item_bottom {
		height: 150rpx;
		display: flex;
		align-items: center;
		border-top: 2rpx solid #f2f2f2;
		.edit {
			width: 100%;
			height: 100%;
			display: flex;
			align-items: center;
			justify-content: space-between;
			button {
				width: 45%;
				height: 80rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				margin: 0;
				border: 1rpx solid #fff;
			}
		}
		.resolve {
			width: 100%;
			height: 100%;
			display: flex;
			align-items: center;
			justify-content: flex-end;
			button {
				width: 45%;
				height: 80rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				margin: 0;
				border: 1rpx solid #fff;
			}
		}
	}
}
</style>
